# 矩阵相加
A = [[1, 3, 5], [7, 9, 11], [13, 15, 17], [100, 200, 300]]
B = [[9, 8, 7], [6, 5, 4],[3, 2, 1], [500, 600, 700]]
D = [[-1, -2],[-10, -20],[-100,-200]]

def Matrix_plus_2div(A:list, size_1div_A:int, size_2div_A:int, B:list, size_1div_B:int, size_2div_B:int):
    if size_1div_A != size_1div_B or size_2div_A != size_2div_B:
        print("Error! Size of A and B Must be SAME!")
        return None
    size_row = size_1div_A
    size_col = size_2div_A
    C = [[None] * size_col for row in range(size_row)]
    for i in range(size_row):
        for j in range(size_col):
            C[i][j] = A[i][j] + B[i][j]
    for i in range(size_row):
        for j in range(size_col):
            print(C[i][j], end=' ')
        print()

# Matrix_plus_2div(A,4,3,B,4,3)


def Matrix_Multiply_2div(A:list, size_1div_A:int, size_2div_A:int, B:list, size_1div_B:int, size_2div_B:int):
    if size_2div_A != size_1div_B :
        print("Error! Size of A's col and B's row Must be SAME!")
        return None
    size_row = size_1div_A
    size_col = size_2div_B
    size_num = size_2div_A
    C = [[None] * size_col for row in range(size_row)]
    print(A)
    print(B)
    print(C)
    for i in range(size_row):
        for j in range(size_col):
            for k in range(size_num):
                temp = 0
                temp += A[i][k]*B[k][j]
                C[i][j] = temp
    for i in range(size_row):
        for j in range(size_col):
            print(C[i][j], end=' ')
        print()

# Matrix_Multiply_2div(A,4,3,D,3,2)

def Matrix_Transposition_2div(A:list, size_1div_A:int, size_2div_A:int):
    size_col_B = size_1div_A
    size_row_B = size_2div_A
    B = [[None] * size_col_B for row in range(size_row_B)]
    for i in range(size_col_B):
        for j in range(size_row_B):
            B[j][i] = A[i][j]
    for i in range(size_row_B):
        for j in range(size_col_B):
            print(B[i][j], end=' ')
        print()


# Matrix_Transposition_2div(A,4,3)




f_a = [0,2,2,3,-2]
g_a = [5,0,-1,1,1]
Size_f = len(f_a)
Size_g = len(g_a)
FmG = list()
for i in range(Size_f):
    for j in range(Size_g):
        FmG.append(f_a[i]*g_a[j])
print("f*g =",end=' ')
for i in range(len(FmG)):
    print(" + {}*x^{}".format(FmG[i],len(FmG)-i),end='')